// run: $exec < input
#include <iostream>
#include <cstring>
#include <cmath>

typedef long long v_type;

v_type a, b, p;

v_type gcd(v_type a, v_type b)
{
	return (!b) ? a : gcd(b, a % b);
}

v_type quick(v_type a, v_type b, v_type p)
{
	if (!b) return 1;
	v_type ret = quick(a, b/2, p);
	ret = (ret * ret) % p;
	if (b & 1) ret *= a;
	return ret % p;
}

namespace hash
{
	int const maxlen = 1299721;
	bool hashed[maxlen];
	v_type key[maxlen];
	int value[maxlen];

	void init()
	{
		std::memset(hashed, 0, sizeof(hashed));
		std::memset(key, 0, sizeof(key));
	}

	void insert(v_type k, int v)
	{
		int i = k % maxlen;
		for (; hashed[i] && key[i] != k; i = (i + 1) % maxlen);
		if (!hashed[i]) { hashed[i] = true; key[i] = k; value[i] = v; }
	}

	int find(v_type k)
	{
		v_type i = k % maxlen;
		for (; hashed[i] && key[i] != k; i = (i + 1) % maxlen);
		if (!hashed[i]) return -1;
		return value[i];
	}
};

v_type euler_totient(int x) // is x prime? FIXME
{
	return x - 1;
}

void extended_gcd(v_type a,  v_type b, v_type & d, v_type & x, v_type & y)
{
	if (!b) { d = a; x = 1; y = 0; }
	else {
		extended_gcd(b, a % b, d, y, x);
		y -= x * (a/b);
	}
}

v_type inverse(v_type t, v_type p)
{
	v_type x, y, d;
	extended_gcd(t, p, d, x, y);
	return (x % p + p) % p;
}

// univariate_modular_system_of_linear_equation
v_type umsole(v_type a, v_type b, v_type p)
{
	// a*x  is congruent to  b  modulo  p
	// => a*x + p*(-y) = b
	v_type x, y, b0;
	extended_gcd(a, p, b0, x, y);
	v_type m = p / b0;
	return ((x * (b / b0)) % m + m) % m;
}

v_type bsgs(v_type a, v_type b, v_type p)
{
	v_type m = std::ceil(std::sqrt((double)euler_totient(p)));
	hash::init();
	v_type d = 1;
	for (int i = 0; i < m; i++) {
		hash::insert(d, i);
		d = (d * a) % p;
	}

	// now d = a^m
	v_type di = 1; // d^i
	for (int i = 0; i < m; i++) {
		v_type x = umsole(di, b, p);
		int tmp  = hash::find(x);
		if (tmp != -1)
			return i * m + tmp;
		di = (di * d) % p;
	}
	return -1;
}


v_type ex_bsgs(v_type a, v_type b, v_type p)
{
	int upper = std::ceil(std::log((double)p)/std::log(2.0));
	upper = 100;
	b %= p; a %= p;
	v_type tmp = 1 % p, count = 0, di = 1, ta;
	for (int i = 0; i <= upper; i++, tmp = (tmp * a) % p)
		if (tmp == b) return i;

	for (v_type d; (d = gcd(a, p)) != 1; count++, di *= d, p /= d, b /= d)
		if (b % d) return -1;

	ta = quick(a, count, p);

	v_type tt = inverse((ta * inverse(di, p)) % p, p);
	tmp = bsgs(a, (tt * b) % p, p);
	if (tmp == -1) return -1;
	return tmp + count;
}

int main()
{
	std::ios::sync_with_stdio(false);
	while (std::cin >> a >> p >> b) {
		v_type ans = -1;
		if (b < p) ans = ex_bsgs(a, b, p);
		if (ans == -1)
			std::cout << "Orz,I can’t find D!\n";
		else
			std::cout << ans << '\n';
	}
}

